#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using System;
using System.Text;

namespace Neatly.UI
{
    public class UIHelper
    {
        public static bool IsEmojiString(string label)
        {
            for (int x = 0; x < label.Length; x++)
            {
                if (IsEmojiCharacter(label[x]))
                {
                    return true;
                }
            }
            return false;
        }

        public static bool IsEmojiCharacter(int codePoint)
        {
            return (codePoint >= 0x2600 && codePoint <= 0x27BF) // 杂项符号与符号字体
                    || codePoint == 0x303D  //中日韩统一符号(CJK)
                    || codePoint == 0x2049  //通用符号
                    || codePoint == 0x203C

                    //添加
                    || codePoint == 0x00A9 || codePoint == 0x00AE   //拉丁符号
                    || IsIn(codePoint, 0x2194, 0x2199)              //箭头
                    || IsIn(codePoint, 0x21A9, 0x21AA)              //箭头
                    || IsIn(codePoint, 0x25AA, 0x25AB)              //几何图形
                    || IsIn(codePoint, 0x25FB, 0x25FE)              //几何图形
                    || codePoint == 0x25B6 || codePoint == 0x25C0   //几何图形
                    || codePoint == 0x3030   //中日韩统一符号(CJK)
                    //End

                    || IsIn(codePoint, 0x2000, 0x200F)
                    || IsIn(codePoint, 0x2028, 0x202F)
                    || codePoint == 0x205F
                    || IsIn(codePoint, 0x2065, 0x206F)
                    || IsIn(codePoint, 0x2100, 0x214F)              // 字母符号
                    || IsIn(codePoint, 0x2300, 0x23FF)              //各种技术符号
                    || IsIn(codePoint, 0x2B00, 0x2BFF)              // 箭头A
                    || IsIn(codePoint, 0x2900, 0x297F)              // 箭头B
                    || IsIn(codePoint, 0x3200, 0x32FF)              // 中文符号
                    || IsIn(codePoint, 0xD800, 0xDFFF)              // 高低位替代符保留区域
                    || IsIn(codePoint, 0xE000, 0xF8FF)              // 私有保留区域
                    || IsIn(codePoint, 0xFE00, 0xFE0F)              // 变异选择器
                    || codePoint >= 0x10000; // Plane在第二平面以上的，char都不可以存，全部都转
                    //|| codePoint == 0x3297 || codePoint == 0x3299   //中日韩统一字母(CJK)
        }

        public static string FormatStringNoEmoji(string str)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < str.Length; i++)
            {
                if (IsEmojiCharacter(str[i])) continue;
                sb.Append(str[i]);
            }
            return sb.ToString();
        }

        public static bool IsIn(int codePoint, int min, int max)
        {
            return codePoint >= min && codePoint <= max;
        }

        public static bool IsSpace(char ch)
        {
            return ch == ' '; // || ch == 0x200a || ch == 0x200b || ch == '\u2009'
        }

        public static string GetConvertedString(string inputString)
        {
            string[] converted = inputString.Split('-');
            for (int j = 0; j < converted.Length; j++)
            {
                converted[j] = char.ConvertFromUtf32(Convert.ToInt32(converted[j], 16));
            }
            return string.Join(string.Empty, converted);
        }
    }
}
